package com.tzl.excep;

import com.tzl.utils.ResponseEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BusinessException extends RuntimeException {
	private Integer code;   // 错误代码
	private String message; // 错误信息
	//通过错误信息创建 BusinessException。
	public BusinessException(String message) {
		this.message = message;
	}
	//通过错误信息和错误代码创建 BusinessException。
	public BusinessException(String message, Integer code) {
		this.message = message;
		this.code = code;
	}
	//通过错误信息、错误代码和原因创建 BusinessException。
	public BusinessException(String message, Integer code, Throwable cause) {
		super(cause);
		this.message = message;
		this.code = code;
	}
	//通过 ResponseEnum 枚举类型创建 BusinessException。
	public BusinessException(ResponseEnum resultCodeEnum) {
		this.message = resultCodeEnum.getMessage();
		this.code = resultCodeEnum.getCode();
	}
	//通过 ResponseEnum 枚举类型和原因创建 BusinessException。
	public BusinessException(ResponseEnum resultCodeEnum, Throwable cause) {
		super(cause);
		this.message = resultCodeEnum.getMessage();
		this.code = resultCodeEnum.getCode();
	}
}
